package com.zj.leetcode.easy;

/**
 * @program: algorithm
 * @description:
 * 696. 计数二进制子串
 * @author: Zhang Bo
 * @create: 2022-01-11 17:29
 **/
public class CountBinarySubstrings{
    public static void main(String[] args) {
        Solution solution = new CountBinarySubstrings().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int countBinarySubstrings(String s) {
            int ptr = 0, n = s.length(), last = 0, ans = 0;
            while (ptr < n) {
                char c = s.charAt(ptr);
                int count = 0;
                while (ptr < n && s.charAt(ptr) == c) {
                    ++ptr;
                    ++count;
                }
                ans += Math.min(count, last);
                last = count;
            }
            return ans;
        }

    }
//leetcode submit region end(Prohibit modification and deletion)

}